package image;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 * *Helper class for ImageLoader
 * A sprite representing an image to displayed on screen. Allows duplication
 * of an image without storing multiple copies.
 *  
 * @author Neil Cowzer
 */
public class Image {
	/** The image to be drawn for this Image */
	private /*@ non_null @*/ BufferedImage image;
	
	/**
	 * Create a new Image based on an a BufferedImage
	 * 
	 * @param image The image that is this Image
	 */
	/*@ requires image != null;
	 	assignable image;
	   	ensures \result == image;
	 @*/
	public Image(BufferedImage image) {
		this.image = image;
	}
	
	/**
	 * Get the width of the Image
	 * 
	 * @return The width of this Image
	 */
	public /*@ pure @*/ int getWidth() {
		return image.getWidth(null);
	}

	/**
	 * Get the height of the Image
	 * 
	 * @return The height of this Image
	 */
	public /*@ pure @*/ int getHeight() {
		return image.getHeight(null);
	}
	
	/**
	 * Get the BufferedImage
	 * 
	 * @return The the BufferedImage
	 */
	public /*@ pure @*/ BufferedImage getBufferedImage() {
		return image;
	}
	
	/**
	 * Draw the sprite onto the graphics context provided
	 * 
	 * @param g The graphics context on which to draw the Image
	 * @param x The x location at which to draw the Image
	 * @param y The y location at which to draw the Image
	 */
	/*@ requires g != null && x != null && y != null;
	 	ensures true;
 	@*/
	public void draw(Graphics g,int x,int y) {
		g.drawImage(image,x,y,null);
	}
}
